package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo05FlatMap {
  def main(args: Array[String]): Unit = {

    /**
     * flatMap：转换算子
     * 传入一行返回N（N>=1）行
     * 需要接收的函数f返回一个集合或者是数组，最终会进行扁平化处理
     */
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName(this.getClass.getSimpleName.replace("$", ""))
    val sc = new SparkContext(conf)

    val rdd: RDD[String] = sc.parallelize(List("java,java,java", "spark,spark", "scala,scala"))

    rdd
      .flatMap(line=>line.split(","))
      .foreach(println)


  }

}
